// pages/spxiangq/spxiangq.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    openid: '',
    details: '', //详情数据
    gkshouji: '', 

    flag: true, //节流

    jif: '',
  },

  back() {
    wx.navigateBack({
      delta: 1
    })
  },



  





  zhuce() {
    this.setData({
      jiami: app.globalData.jiami,
      openid: app.globalData.openid,
      session_key: app.globalData.session_key,
    })
    wx.request({
      url: app.globalData.interface+'/shangluo/API_8303_SelectshangluoUserIntegral',
      method: 'POST',
      data: {
        OPEN_ID: app.globalData.openid, //用户OPEN_ID
        session_key: app.globalData.session_key,
        OPEN_UUID: app.globalData.jiami,

      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        this.setData({
          jif: res.data.data.INTEGRAL,
          gukname: res.data.data.CUSTOMER_NAME,
          gkshouji: res.data.data.CUSTOMER_TEL,
        })
      }
    })
  },


  exhibits() {

    let that = this

    if (that.data.flag) {
      that.data.flag = false



    wx.request({
      url: app.globalData.interface+'/shangluo/API_8307_ExchangeshangluoIntegralGood',
      method: 'POST',
      data: {
        GOODS_ID: that.data.details.GOODS_ID,
        GOODSUSERNAME: that.data.gukname,
        GOODSPHONE:  that.data.gkshouji,
        OPEN_ID: app.globalData.openid, //用户OPEN_ID
        session_key: app.globalData.session_key,
        OPEN_UUID: app.globalData.jiami,

      },
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success: res => {
        
        if( res.data.result == "error"){
          wx.showModal({
            title: '温馨提示',
            content: res.data.data,
            success: function (res) {
              if (res.confirm) {//这里是点击了确定以后
                console.log('用户点击确定')
              } else {//这里是点击了取消以后
                console.log('用户点击取消')
              }
            }
          })
        }else{//带工号跳转
          wx.showModal({
            title: '温馨提示',
            content: res.data.data,
            success: function (res) {
              if (res.confirm) {//这里是点击了确定以后
                that.zhuce()
              } else {//这里是点击了取消以后
                that.zhuce()
              }
            }
          })
        }
      }
    })

    setTimeout(() => {
      that.data.flag = true
    }, 3000)


  }
  },






  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(e) {

    console.log(e.data);


      console.log(JSON.parse(e.data));
      let diyiid = JSON.parse(e.data)
      console.log(diyiid);

      this.setData({
        details: diyiid,
 
      })



  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

    this.setData({
      jiami: app.globalData.jiami,
      OPEN_ID: app.globalData.openid,
      openid: app.globalData.openid,
      session_key: app.globalData.session_key,
    });

    this.zhuce()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  },
})